<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"/>
<%@ include file="/commons/jsp/taglibs.jsp"%>
<%@taglib prefix="frame" uri="http://www.framework.com/taglib"%>
       <div>
         <input type="hidden" name="projectId" value="${projectId}" id="projectId"/> 	       
       <div class="easyui-panel" data-options="border:true,title:'非中标保证金'" style="height:260px;padding: 1px;margin-bottom: 6px">
         <table id="mydialog" class="easyui-datagrid" 
					data-options="singleSelect:false,method:'post',rownumbers:true,fit:true,fitColumns:true,border:true,
						pagination:false,multiSort:true,remoteSort:true,striped:true,height:300,
						url:'${ctx}/business/projectmanage/leader/getProjectBidList?projectId=${projectId}&type=0&pageSize=100'">
					<thead>
						<tr>
							<th data-options="field:'pk',width:150,title:'单位名称',formatter:fromatterCompanyName" align="center"></th>
							<th data-options="field:'tnAmount',width:100,title:'缴纳金额',sortable:true" align="center"></th>
							<th data-options="field:'transTime',width:150,title:'缴纳时间',sortable:true" align="center"></th>
							<th data-options="field:'hstSeqNum',width:150,title:'交易流水号',sortable:true,formatter:fromatterHstSeqNum" align="center"></th>
							<th data-options="field:'bid',width:80,title:'是否投标',sortable:true,formatter:formatBid" align="center"></th>
							<th data-options="field:'returnOpt',width:80,title:'是否提交退还申请',sortable:true,formatter:formatOpt" align="center"></th>
							<th data-options="field:'addWord',width:80,title:'中间状态',sortable:true"align="center"></th>
							<th data-options="field:'status',width:140,title:'退还状态',sortable:true,formatter:formatStatus" align="center"></th>
							<th data-options="field:'operation',width:80,title:'操作',formatter:formatbutton" align="center"></th>
					</tr>
					</thead>
			</table>
         </div>
      <!--    <div id="tb">
               <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick="returnUnBidDeposit();">退还保证金</a>
         </div> -->
         
         <c:if test="${isShowBid}">
         <div class="easyui-panel" data-options="border:true,title:'中标保证金'" style="height:160px;padding: 1px;margin-bottom: 6px">
          <table id="mydialog2" class="easyui-datagrid"data-options="singleSelect:false,method:'post',rownumbers:true,fit:true,fitColumns:true,border:true,
						pagination:false,multiSort:true,remoteSort:true,striped:true,height:300,
						url:'${ctx}/business/projectmanage/leader/getProjectBidList?projectId=${projectId}&type=1'">
					<thead>
						<tr>
							<th data-options="field:'pk',width:150,title:'单位名称',formatter:fromatterCompanyName" align="center"></th>
							<th data-options="field:'tnAmount',width:100,title:'缴纳金额',sortable:true" align="center"></th>
							<th data-options="field:'transTime',width:150,title:'缴纳时间',sortable:true" align="center"></th>
							<th data-options="field:'hstSeqNum',width:150,title:'交易流水号',sortable:true,formatter:fromatterHstSeqNum" align="center"></th>
							<th data-options="field:'bid',width:80,title:'是否投标',sortable:true,formatter:formatBid" align="center"></th>
							<th data-options="field:'returnOpt',width:80,title:'是否提交退还申请',formatter:formatOpt" align="center"></th>
							<th data-options="field:'addWord',width:80,title:'中间状态',sortable:true"align="center"></th>
							<th data-options="field:'status',width:140,title:'退还状态',sortable:true,formatter:formatStatus" align="center"></th>
							<th data-options="field:'operation',width:80,title:'操作',formatter:formatbutton2" align="center"></th>
					   </tr>
					</thead>
			</table> 
         </div> 
        <!--  <div id="tb1">
               <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick=" returnDeposit();">退还保证金</a>
         </div> -->
         </c:if> 
         <c:if test="${showButtonFlag}">   
	        <tr>
	         	<td colspan="4">
			       <center><a id="submit" class="easyui-linkbutton" onclick="finishDepositReturnt()">结束退还保证金</a></center> 
			    </td> 
			</tr>
		 </c:if>    
       </div>
	    <script type="text/javascript">
	     var projectId=$("#projectId").val();        
	    // 是否投标格式化  
						function formatStatus(val, row, index) {
							if (row.status == 0) {
								return '<font color="blue">未退还</font>';
							} else if (row.status == 1) {
								return '<font color="green">已退还</font>';
							} else if (row.status == 2) {
								return '<font color="red">扣除</font>';
							}else if(row.status==-1){
								return '<font color="orange">退还失败</font>';
							}

						}

						//是否提交申请格式化	    
						function formatOpt(val, row, index) {
							if (row.returnOpt == 0) {
								return '<font color="blue">未申请</font>';
							} else if (row.returnOpt == 1) {
								return '<font color="green">申请成功</font>';
							}else if (row.returnOpt == -1){
								return '<font color="orange">申请超时</font>';
							}else if(row.returnOpt == 2){
								return '<font color="red">申请失败</font>';
							}
						}

						//是否投标    
						function formatBid(val, row, index) {
							if (row.isBid == false) {
								return '<font color="red">未投标</font>';
							} else if (row.isBid == true) {
								return '<font color="green">已投标</font>';
							}
						}

						//单位名
						function fromatterCompanyName(val, row, index) {
							if (row.pk) {
								return row.pk.companyName;
							}
						}
						
						//流水号
						function fromatterHstSeqNum(val, row, index) {
							if (row.pk) {
								return row.pk.hstSeqNum;
							}
						}
						
						
						//操作按钮(非中标)
						   function formatbutton(val, row, index){
					    	   if(row.status!=1){
					    		   return '<button  onclick="returnUnBidDeposit(\'' + row.pk.projectId+ '\',\'' + row.bidderId+ '\',\'' + row.pk.hstSeqNum+ '\')" class=""><font color="green">退还</font></button>';	
					    	   }else {
					    		   return '<button  onclick="" disabled="true" class=""><font color="red">退还</font></button>';	
					    	   }
					       }
						 //操作按钮(中标)
						   function formatbutton2(val, row, index){
					    	   if(row.status!=1){
					    		   return '<button  onclick="returnBidDeposit(\'' + row.pk.projectId+ '\',\'' + row.bidderId+ '\',\'' + row.pk.hstSeqNum+ '\')" class=""><font color="green">退还</font></button>';	
					    	   }else {
					    		   return '<button  onclick="" disabled="true" class=""><font color="red">退还</font></button>';	
					    	   }
					       }

						// 完成保证金操作
						function finishDepositReturnt() {
							$.ajax({type : 'post',
										url : '${ctx}/business/projectmanage/leader/getReturnList',
										data : {
											projectId : $("#projectId").val(),
											depositType:0
										},
										success : function(data) {
											if (data == "unPass") {
												$.messager.alert('提示信息','存在已提交退款申请，银行未完成退还的状态！','error');
											} else if (data == "allreturn") {
												$.messager.confirm('提示信息','是否确认保证金退还操作完成？',
																function(r) {
																	if (r) {
																		$.ajax({
																					type : 'post',
																					url : '${ctx}/business/projectmanage/leader/finishDepositReturn',
																					data : {
																						projectId : $("#projectId").val(),
																						depositType:0
																					},
																					success:function(){
																						top.$('#threeLevelDialog').dialog('close');
																						
																					},

																				});
																	}
																});
											} else if (data == "unallreturn") {
												$.messager.confirm('提示信息','本项目尚存在未退还保证金，是否确认扣除这些投标人的保证金并完成保证金退还操作？',
																function(r) {
																	if (r) {
																		$.ajax({
																					type : 'post',
																					url : '${ctx}/business/projectmanage/leader/finishDepositReturn',
																					data : {
																						projectId : $("#projectId").val(),
																						depositType:0
																					},
																					success:function(){
																						top.$('#threeLevelDialog').dialog('close');
																						
																					},
																				});
																	}
																});
											}
										}
									});

						}


						
				     //退还非中标保证金
						function returnUnBidDeposit(projectId,bidderId,hstSeqNum) {
							$.messager.confirm('确认对话框','是否退还保证金？',
											function(r) {
												if(r){
												loading();//加载数据loading
													$.ajax({    type : 'post',
																url : '${ctx}/business/projectmanage/leader/returnDeposit',
																data : {
																	projectId : projectId,
																	projectName : null,
																	bidderId:bidderId,
																	hstSeqNum:hstSeqNum
																},
																success : function(data) {
																	if(data=="bankTimeOut"){
																		 top.$.messager.alert('提示信息','银行超时无响应！','error',function(){
																				top.$('#secondtLevelDialog').dialog('close');//关闭加载数据
																				$('#mydialog').datagrid('reload');	
																		 });
																	}else if(data=="noExecuteDeposit"){
																		 top.$.messager.alert('提示信息','未缴纳履约保证金，无法退还中标保证金！','error',function(){
																				top.$('#secondtLevelDialog').dialog('close');//关闭加载数据
																				$('#mydialog').datagrid('reload');	
																		 });
																	}else if(data=="saveSuccess"){
																		 top.$.messager.alert('提示信息','退还申请成功,请等待银行处理结果！','info',function(){
																				top.$('#secondtLevelDialog').dialog('close');//关闭加载数据
																				$('#mydialog').datagrid('reload');	
																		 });
																	}else if(data=="saveUnsuccess"){
																		 top.$.messager.alert('提示信息','退还申请失败，请确认后重新提交申请！','error',function(){
																				top.$('#secondtLevelDialog').dialog('close');//关闭加载数据
																				$('#mydialog').datagrid('reload');	
																		 });
																	}
																
																}
															});}
											});
						              }
						
                     //退还中标保证金
						function returnBidDeposit(projectId,bidderId,hstSeqNum) {
							$.messager.confirm('确认对话框','是否退还保证金？',
											function(r) {
								              if(r){
												//加载数据loading
												loading();
													$.ajax({    type : 'post',
																url : '${ctx}/business/projectmanage/leader/returnDeposit',
																data : {
																	projectId : projectId,
																	projectName : null,
																	bidderId:bidderId,
																	hstSeqNum:hstSeqNum
																},
																success : function(data) {
																	if(data=="bankTimeOut"){
																		 top.$.messager.alert('提示信息','银行超时无响应！','error',function(){
																				top.$('#secondtLevelDialog').dialog('close');//关闭加载数据
																				$('#mydialog2').datagrid('reload');	
																		 });
																	}else if(data=="noExecuteDeposit"){
																		 top.$.messager.alert('提示信息','未缴纳履约保证金，无法退还中标保证金！','error',function(){
																				top.$('#secondtLevelDialog').dialog('close');//关闭加载数据
																				$('#mydialog2').datagrid('reload');	
																		 });
																	}else if(data=="saveSuccess"){
																		 top.$.messager.alert('提示信息','退还申请成功,请等待银行处理结果！','info',function(){
																				top.$('#secondtLevelDialog').dialog('close');//关闭加载数据
																				$('#mydialog2').datagrid('reload');	
																		 });
																	}else if(data=="saveUnsuccess"){
																		 top.$.messager.alert('提示信息','退还申请失败，请确认后重新提交申请！','error',function(){
																				top.$('#secondtLevelDialog').dialog('close');//关闭加载数据
																				$('#mydialog2').datagrid('reload');	
																		 });
																	}
																
																}
															});
								              }
											});
						              }



		 function loading(){
				top.$('#secondtLevelDialog').dialog({
				closable: false,
			    title:'数据加载',
			    width: '300',    
			    height: '180',    
			    closed: false,    
			    inline : true,
			    cache: false,    
			    href: "${ctx}/commons/js/loading/loading.html",
			    modal: true,
				extractor : function(data){
					if($.trim(data) == "unLogin"){
						var msn = ''||i18n[''];
						msn = msn||i18n[data];
						if(msn != undefined){
							top.$.messager.alert('提示',msn,'info',function(){top.location='${ctx}/user-login-sys-new/loginPwd';});
							return '';
						}
					}
					return data;
				}
				});
				top.$('#secondtLevelDialog').dialog("center");
			}
           </script>

                 
   
  
